package cn.bugDance.test.domain.rebate;


import cn.bugDance.domain.activity.service.armory.IRaffleActivityArmory;
import cn.bugDance.domain.rebate.model.entity.BehaviorEntity;
import cn.bugDance.domain.rebate.service.IRebateService;
import cn.bugDance.domain.strategy.service.armory.IRaffleStrategyArmory;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

@SpringBootTest
@RunWith(SpringRunner.class)
@Slf4j
public class SignInTest {

    @Resource
    private IRaffleActivityArmory raffleActivityArmory;
    @Resource
    private IRaffleStrategyArmory raffleStrategyArmory;

    @Autowired
    @Qualifier("calendarSignRebateService")
    private IRebateService rebateService;

    private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private final SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM");



    public void init(){
        Long strategyId = raffleActivityArmory.assembleRaffleActivity(100301L);
        Date endTime = raffleActivityArmory.queryActivityEndTime(100301L);
        raffleStrategyArmory.assembleRaffleStrategy(strategyId, endTime);
    }

    @Test
    public void test_sign() throws InterruptedException {
        Date nowDate = new Date();
        BehaviorEntity behaviorEntity = new BehaviorEntity();
        behaviorEntity.setUserId("yangxiaocan");
        behaviorEntity.setNowDate(nowDate);
        behaviorEntity.setActivityId(100301L);
        behaviorEntity.setBehaviorType("CHECK_IN");
        behaviorEntity.setSignDay(dateFormat.format(nowDate));
        behaviorEntity.setSignMonth(monthFormat.format(nowDate));

        rebateService.createUserBehaviorRebateOrder(behaviorEntity);
        new CountDownLatch(1).await();
    }
}
